"use strict"

// 使用到的库
// <script src="js/g2.min.js" type="text/javascript" charset="utf-8"></script>
// <script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>
// <script src="js/data-set.min.js" type="text/javascript" charset="utf-8"></script>
// <script src="js/PerfUtils.js" type="text/javascript" charset="utf-8"></script>

/**---------------------全局变量定义 Start-----------------------**/

var urlPrefix = 'http://127.0.0.1:8080/PerfAutoTestV1.4/';

/**---------------------全局变量定义 End-----------------------**/

/**---------------------工具方法 Start-----------------------**/

// 获取url参数信息
function GetParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) {
		return decodeURI(r[2]);
	}
	return null;
}

// Post请求
function doPost(urlParam, bodyParam) {

	var responseJson = $.parseJSON($.ajax({
		async: false,
		type: 'post',
		url: urlPrefix + urlParam,
		data: bodyParam
	}).responseText);

	return responseJson;
}

// Post请求Str
function doPostStr(urlParam, bodyParam) {

	var responseStr = $.ajax({
		async: false,
		type: 'post',
		url: urlPrefix + urlParam,
		data: bodyParam
	}).responseText;

	return responseStr;
}

// 获取jsonarry长度
function getJsonArryLength(json) {
	var jsonLength = 0;
	for (var i in json) {
		jsonLength++;
	}
	return jsonLength;
}

// 根据id，设置可编辑属性
function setContenteditableById(id) {

	document.getElementById(id).setAttribute('contenteditable', 'true');
	document.getElementById(id).setAttribute('style', 'background: #5cb85c;');
	console.info('setContenteditableById done');
}

// 根据class，设置所有为可编辑属性
function setContenteditableByClass(className) {

	var eles = document.getElementsByClassName(className);
	for (var i = 0; i < eles.length; i++) {
		eles[i].style.backgroundColor = '#5cb85c';
		eles[i].contentEditable = 'true';
	}

	console.info('setContenteditableByClass done');
}

// js获取复选框
function getChecked(checkboxname){
    var checkboxs = document.getElementsByName(checkboxname);
    var check_val = [];
		
    for(var k in checkboxs){
        if(checkboxs[k].checked){
					var check_obj = {};
					check_obj.interface = checkboxs[k].value;
					check_val.push(check_obj)
				}
    }
		return check_val;
}

/**---------------------工具方法 End-----------------------**/

/**---------------------接口详情方法 Start-----------------------**/

// 绘制页面表格：几个单板就用几个div，同时可以选择测试工具
function initDetailPage(boards, tools) {

	// 生成侧边栏里面的接口列表
	getInterfaceOfVersion(version);
	
	// 设置侧边栏-版本概要的url
	document.getElementById("switchtointerfaces").href = 'interfaces.html?version=' + version;

	// 设置当前选中的侧边栏接口高亮
	document.getElementById(interfaceDesc + 'aid').className = 'open';
	
	var baseInfoDivPart =
		'<!-- baseInfoDiv Start --><div class="widget"><div class="widget-head"><div class="pull-left">Base Info</div><div class="widget-icons pull-right"><a href="#" class="wminimize"><i class="icon-chevron-down"></i></a><a href="#" class="wclose"><i class="icon-remove"></i></a></div><div class="clearfix"></div></div><div class="widget-content" style="display: none;"><div style="width:100px; position:relative; left:1300px; top:20px; z-index: 999;"><select style="font-size: 1px;" class="form-control" onchange="switchBaseChart(this.options[this.options.selectedIndex].value)"><option>TPS</option><option>Delay</option><option>ErrorCount</option></select></div><div id="baseInfoDiv"></div></div></div><!-- baseInfoDiv End -->';

	var boardInfoDivPart = '';
	for (var i in boards) {

		var boardStr = boards[i];

		boardInfoDivPart = boardInfoDivPart +
			'<!-- boardInfoDiv Start --><div class="widget"><div class="widget-head"><div class="pull-left">' + boardStr +
			' Info</div><div class="widget-icons pull-right"><a href="#" class="wminimize"><i class="icon-chevron-down"></i></a><a href="#" class="wclose"><i class="icon-remove"></i></a></div><div class="clearfix"></div></div><div class="widget-content" style="display: none;"><div style="width:150px; position:relative; left:1300px; top:20px; z-index: 999;"><select style="font-size: 1px;" class="form-control" onchange="switchBoardChart(this.options[this.options.selectedIndex].value, \'' +
			boardStr +
			'\')"><option>单板CPU占用</option><option>进程CPU占用</option><option>MemFree</option><option>VIRT</option><option>MemUsed</option><option>网络接收</option><option>网络发送</option><option>TCP ESTABLISHED</option><option>TCP TIME_WAIT</option><option>磁盘IO队列</option><option>磁盘IO： 读</option><option>磁盘IO： 写</option><option>自定义</option></select></div><div id="' +
			boardStr + '"></div></div></div><!-- boardInfoDiv End -->';
	}

	var switchToolsInner = '';
	for (var i in tools) {

		switchToolsInner = switchToolsInner + '<option>' + tools[i] + '</option>';
	}
	document.getElementById('switchTools').innerHTML = switchToolsInner;

	var reportPart = '<div class="widget"><div class="widget-head"><div class="pull-left">测试工具报告</div><div class="widget-icons pull-right"><a href="#" class="wminimize"><i class="icon-chevron-down"></i></a> <a href="#" class="wclose"><i class="icon-remove"></i></a></div><div class="clearfix"></div></div><div class="widget-content" style="display: none;"><table class="table table-striped table-bordered table-hover" id="reportTable"><thead><tr><th>#</th><th>测试工具</th><th>Vusers</th><th>测试报告</th></tr></thead><tbody id="reporttBody"><tr><td>#</td><td></td><td></td><td></td></tr></tbody></table></div></div>';

	var ScrollPart = '<!-- Scroll to top --><span class="totop"><a href="#"><i class="icon-chevron-up"></i></a></span>';

	document.getElementById('detailContainer').innerHTML = baseInfoDivPart + boardInfoDivPart + reportPart + ScrollPart;
	console.info('initDetailPage done...');
}

function initDetailChart() {

	baseInfoChart('baseInfoDiv', 'tps', '/s');
	for (var i in boards) {
		boardInfoChart(boards[i], boards[i], 'cpu', '%')
	}
	
	// 添加测试报告表格
	var reportInfoJson = doPost('ReportInfoGet', '{"version":"' + version + '", "interfaceDesc":"' + interfaceDesc + '"}');
	var reportMessage = reportInfoJson['message'];
	
	var reportInner = '';
	
	for (var i in reportMessage) {
		console.info(reportMessage[i]);
		reportInner = reportInner + '<tr><td>#</td>';
		
		reportInner = reportInner + '<td>' + reportMessage[i]['tool'] + '</td>';
		reportInner = reportInner + '<td>' + reportMessage[i]['vusers'] + '</td>';
		reportInner = reportInner + '<td><a href="' + urlPrefix + reportMessage[i]['reportpath'] + '" target="_blank">查看详情</a></td>';
		
		reportInner = reportInner + '</tr>';
	}
	
	document.getElementById('reporttBody').innerHTML = reportInner;
}

// 绘制基本性能信息的曲线图
function switchBaseChart(optionValue) {

	console.info(optionValue)

	switch (optionValue) {
		case 'TPS':
			baseInfoChart('baseInfoDiv', 'tps', '/s');
			break;
		case 'Delay':
			baseInfoChart('baseInfoDiv', 'avgdelay', 'ms');
			break;
		case 'ErrorCount':
			baseInfoChart('baseInfoDiv', 'errorcount', '');
			break;
		default:
			break;
	}
}

function baseInfoChart(divID, metric, unit) {

	// console.info(version)
	// console.info(interfaceDesc)

	var obj = document.getElementById("switchTools"); //定位id
	var index = obj.selectedIndex; // 选中索引
	var tool = obj.options[index].text; // 选中文本

	// console.info('tool: ' + tool);

	document.getElementById(divID).innerHTML = "";

	/**
	 * 传入参数：
	 * 版本名称
	 * 接口名称
	 * 单板名称
	 * 
	 * 返回数据：
	 * 该版本下-该接口-该单板在所有vusers组合下的性能数据
	 */
	var responseJson = doPost('GetBaseInfo', '{"version":"' + version + '", "interfaceDesc":"' +
		interfaceDesc + '", "tool":"' + tool + '"}');
	// console.info(responseJson);

	var os = [];
	var fieldss = [];

	for (var i in responseJson) {

		var vusers = responseJson[i]['vusers'];
		// console.info(vusers);

		fieldss.push(vusers);

		var baseInfoJson = responseJson[i]['baseinfo'];
		// console.info(baseInfoJson);

		for (var j in baseInfoJson) {
			// console.info(baseInfoJson[j]);
			if (os[j] == undefined) {
				os[j] = {};
			}

			os[j].id = j;
			os[j][vusers] = parseFloat(baseInfoJson[j][metric]);
		}

	}
	// console.info(os);

	var ds = new DataSet();
	var dv = ds.createView().source(os);

	// fold 方式完成了行列转换，如果不想使用 DataSet 直接手工转换数据即可
	dv.transform({
		type: 'fold',
		fields: fieldss, // 展开字段集
		key: 'vusers', // key字段
		value: metric // value字段
	});

	var chart = new G2.Chart({
		container: divID,
		// forceFit: true, // 宽度自适应
		width: 1600,
		height: 500,
		padding: [5, 20, 40, 80] // 上右下左
	});

	chart.source(dv, {
		id: {
			range: [0, 1]
		}
	});

	chart.tooltip({
		crosshairs: {
			type: 'line'
		}
	});

	chart.axis('id', {
		label: null
	});

	chart.axis(metric, {
		label: {
			formatter: function formatter(val) {
				return val + unit;
			}
		}
	});

	chart.line().position('id*' + metric).color('vusers').shape('smooth');
	chart.point().position('id*' + metric).color('vusers').size(3).shape('circle').style({
		stroke: '#fff',
		lineWidth: 1
	});

	chart.render();

	// return chart;
}

// 绘制单板详细性能信息的曲线图
function switchBoardChart(optionValue, boardName) {

	// 这里div的id和单板的名称保持一致
	switch (optionValue) {
		case '单板CPU占用':
			boardInfoChart(boardName, boardName, 'cpu', '%');
			break;
		case '进程CPU占用':
			boardInfoChart(boardName, boardName, 'cpuprocess', '%');
			break;
		case 'MemFree':
			boardInfoChart(boardName, boardName, 'memfree', 'MB');
			break;
		case 'VIRT':
			boardInfoChart(boardName, boardName, 'memvirt', 'MB');
			break;
		case 'MemUsed':
			boardInfoChart(boardName, boardName, 'memprocess', 'MB');
			break;
		case '网络接收':
			boardInfoChart(boardName, boardName, 'netreceive', '');
			break;
		case '网络发送':
			boardInfoChart(boardName, boardName, 'netsend', '');
			break;
		case 'TCP ESTABLISHED':
			boardInfoChart(boardName, boardName, 'tcpestab', '');
			break;
		case 'TCP TIME_WAIT':
			boardInfoChart(boardName, boardName, 'tcptimewait', '');
			break;
		case '磁盘IO队列':
			boardInfoChart(boardName, boardName, 'diskqueue', 'kB/s');
			break;
		case '磁盘IO： 读':
			boardInfoChart(boardName, boardName, 'diskreads', 'kB/s');
			break;
		case '磁盘IO： 写':
			boardInfoChart(boardName, boardName, 'diskwrites', '');
			break;
		case '自定义':
			boardInfoChart(boardName, boardName, 'userdefind', '');
			break;
		default:
			break;
	}
}

function boardInfoChart(boardDesc, divID, metric, unit) {

	// console.info(version)
	// console.info(interfaceDesc)

	var obj = document.getElementById("switchTools"); //定位id
	var index = obj.selectedIndex; // 选中索引
	var tool = obj.options[index].text; // 选中文本

	// console.info('tool: ' + tool);

	// console.info('version: ' + version);
	// console.info('interfaceDesc: ' + interfaceDesc);
	// console.info('boardDesc: ' + boardDesc);
	// console.info('divID: ' + divID);
	// console.info('metric: ' + metric);
	// console.info('unit: ' + unit);
	document.getElementById(divID).innerHTML = "";

	/**
	 * 传入参数：
	 * 版本名称
	 * 接口名称
	 * 单板名称
	 * 
	 * 返回数据：
	 * 该版本下-该接口-该单板在所有vusers组合下的性能数据
	 */
	var responseJson = doPost('GetBoardInfo', '{"version":"' + version + '", "interfaceDesc":"' +
		interfaceDesc + '", "boardDesc":"' + boardDesc + '", "tool":"' + tool + '"}');
	console.info(responseJson);

	var os = [];
	var fieldss = [];

	for (var i in responseJson) {

		var vusers = responseJson[i]['vusers'];
		// console.info(vusers);

		fieldss.push(vusers);

		var boardInfoJson = responseJson[i]['boardinfo'];
		// console.info(boardInfoJson);

		for (var j in boardInfoJson) {
			// console.info(boardInfoJson[j]);
			if (os[j] == undefined) {
				os[j] = {};
			}

			os[j].id = j;
			os[j][vusers] = parseFloat(boardInfoJson[j][metric]);
		}

	}
	// console.info(os);

	var ds = new DataSet();
	var dv = ds.createView().source(os);

	// fold 方式完成了行列转换，如果不想使用 DataSet 直接手工转换数据即可
	dv.transform({
		type: 'fold',
		fields: fieldss, // 展开字段集
		key: 'vusers', // key字段
		value: metric // value字段
	});

	var chart = new G2.Chart({
		container: divID,
		// forceFit: true, // 宽度自适应
		width: 1600,
		height: 500,
		padding: [5, 20, 40, 80] // 上右下左
	});

	chart.source(dv, {
		id: {
			range: [0, 1]
		}
	});

	chart.tooltip({
		crosshairs: {
			type: 'line'
		}
	});

	chart.axis('id', {
		label: null
	});

	chart.axis(metric, {
		label: {
			formatter: function formatter(val) {
				return val + unit;
			}
		}
	});

	chart.line().position('id*' + metric).color('vusers').shape('smooth');
	chart.point().position('id*' + metric).color('vusers').size(3).shape('circle').style({
		stroke: '#fff',
		lineWidth: 1
	});

	chart.render();

	// return chart;
}

/**---------------------接口详情方法 End-----------------------**/

/**---------------------基本配置文件 Start-----------------------**/

// 改
function setConfig(id) {

	doPost('ConfigSetByName', '{"name":"' + id + '", "value":"' + document.getElementById(id).textContent + '"}');
	document.getElementById(id).setAttribute('style', '');
	getBasicConfig();
	console.info('setConfig: ' + id + ' done');
}

// 查
function getBasicConfig() {

	var responseJson = doPost('ConfigGetByName', '{}')

	document.getElementById("platform").innerText = responseJson["platform"];
	document.getElementById("prefix").innerText = responseJson["prefix"];
	document.getElementById("suffix").innerText = responseJson["suffix"];
	document.getElementById("dalta").innerText = responseJson["dalta"];
	document.getElementById("delay").innerText = responseJson["delay"];
	document.getElementById("user").innerText = responseJson["user"];
	document.getElementById("pw").innerText = responseJson["pw"];
	document.getElementById("monitor_port").innerText = responseJson["monitor_port"];
	document.getElementById("mysql_host").innerText = responseJson["mysql_host"];
	document.getElementById("mysql_port").innerText = responseJson["mysql_port"];
	document.getElementById("mysql_user").innerText = responseJson["mysql_user"];
	document.getElementById("mysql_pw").innerText = responseJson["mysql_pw"];
	document.getElementById("mysql_db").innerText = responseJson["mysql_db"];

	document.getElementById("version").innerText = responseJson["version"];
	document.getElementById("tps_num").innerText = responseJson["tps_num"];
	document.getElementById("avgdelay_num").innerText = responseJson["avgdelay_num"];
	document.getElementById("vusers").innerText = responseJson["vusers"];
	document.getElementById("err_num").innerText = responseJson["err_num"];
}

/**---------------------基本配置文件 End-----------------------**/

/**---------------------单板配置文件 Start-----------------------**/

// 增
function addBoardConfig() {

	var desc = document.getElementById("newdesc").textContent;
	var host = document.getElementById("newhost").textContent;
	var port = document.getElementById("newport").textContent;
	var user = document.getElementById("newuser").textContent;
	var pw = document.getElementById("newpw").textContent;
	var processname = document.getElementById("newprocessname").textContent;

	var bodyJson = {};
	bodyJson.desc = desc;
	bodyJson.host = host;
	bodyJson.port = port;
	bodyJson.user = user;
	bodyJson.pw = pw;
	bodyJson.processname = processname;

	var bodyStr = JSON.stringify(bodyJson);

	console.info(bodyStr);

	doPost('BoardAdd', bodyStr);

	getBoardConfig();

	console.info('addBoardConfig done');
}

// 删
function delBoardConfig(desc) {

	if (confirm('确认删除？')) {
		doPost('BoardDelete', '{"desc":"' + desc + '"}');
	}

	getBoardConfig();

	console.info('delBoardConfig done');
}

// 改
function setBoardConfig(desc) {

	var host = document.getElementById(desc + "_host").textContent;
	var port = document.getElementById(desc + "_port").textContent;
	var user = document.getElementById(desc + "_user").textContent;
	var pw = document.getElementById(desc + "_pw").textContent;
	var processname = document.getElementById(desc + "_processname").textContent;

	var bodyJson = {};
	bodyJson.desc = desc;
	bodyJson.host = host;
	bodyJson.port = port;
	bodyJson.user = user;
	bodyJson.pw = pw;
	bodyJson.processname = processname;

	var bodyStr = JSON.stringify(bodyJson);

	console.info(bodyStr);

	doPost('BoardModify', bodyStr);

	getBoardConfig();

	console.info('setBoardConfig done');
}

// 查
function getBoardConfig() {

	var responseJson = doPost('BoardGet', '{}');
	var length = getJsonArryLength(responseJson);

	var innerHtml = '';
	for (var i in responseJson) {
		var boardJson = responseJson[i];
		innerHtml = innerHtml + '<tr><td id="' + boardJson.desc + '_desc">' + boardJson.desc +
			'</td><td id="' + boardJson.desc + '_host" class="' + boardJson.desc +
			'">' +
			boardJson.host + '</td><td id="' + boardJson.desc + '_port" class="' + boardJson.desc + '">' + boardJson.port +
			'</td><td id="' + boardJson.desc + '_user" class="' + boardJson.desc + '">' + boardJson.user + '</td><td id="' +
			boardJson.desc + '_pw" class="' + boardJson.desc +
			'">' + boardJson
			.pw +
			'</td><td id="' + boardJson.desc + '_processname" class="' + boardJson.desc + '">' + boardJson.processname +
			'</td><td><button class="btn btn-xs btn-success"><i class="icon-ok" onClick="setBoardConfig(\'' + boardJson.desc +
			'\')"></i></button>&nbsp;<button class="btn btn-xs btn-warning"><i class="icon-pencil" onClick="setContenteditableByClass(\'' +
			boardJson.desc +
			'\')"></i></button>&nbsp;<button class="btn btn-xs btn-danger"><i class="icon-remove" onClick="delBoardConfig(\'' +
			boardJson.desc +
			'\')"></i></button></td></tr>';
	}
	innerHtml = innerHtml +
		'<tr><td id="newdesc" contenteditable="true">请新增名称，不能重复</td><td id="newhost" contenteditable="true">请新增地址</td><td id="newport" contenteditable="true">22</td><td id="newuser" contenteditable="true">请新增用户</td><td id="newpw" contenteditable="true">请新增密码</td><td id="newprocessname" contenteditable="true">请新增进程关键字</td><td><button class="btn btn-xs btn-success"><i class="icon-ok" onClick="addBoardConfig()"></i></button></td></tr>';

	document.getElementById('tbody').innerHTML = innerHtml;
	console.info('getBoardConfig done');
}

/**---------------------单板配置文件 End-----------------------**/

/**---------------------接口配置文件 Start-----------------------**/

// 增
function addInterfaceConfig() {

	var desc = document.getElementById("newdesc").textContent;
	var headers = document.getElementById("newheaders").textContent;
	var method = document.getElementById("newmethod").textContent;
	var isAutoScript = document.getElementById("newisautocreatejmx").textContent;
	var bodyStr = document.getElementById("newbody").textContent;
	var boards = document.getElementById("newboards").textContent;
	var jmeterScriptPath = document.getElementById("newjmeter_script_path").textContent;
	var maxDelay = document.getElementById("newmaxdelay").textContent;
	var gatlingScriptPath = document.getElementById("newgatling_script_path").textContent;
	var responseContain = document.getElementById("newresponseContain").textContent;
	var urlStr = document.getElementById("newurl").textContent;

	var bodyJson = {};
	bodyJson.desc = desc;
	bodyJson.isautocreatejmx = isAutoScript;
	bodyJson.jmeter_script_path = jmeterScriptPath;
	bodyJson.gatling_script_path = gatlingScriptPath;
	bodyJson.method = method;
	bodyJson.urlStr = urlStr;
	bodyJson.headersLinkJson = headers;
	bodyJson.body = bodyStr;
	bodyJson.responseContain = responseContain;
	bodyJson.boards = boards;
	bodyJson.maxdelay = maxDelay;

	console.info(bodyJson);

	doPost('InterfaceAdd', JSON.stringify(bodyJson));

	getInterfaceConfig();

	console.info('addInterfaceConfig done');
}

// 删
function delInterfaceConfig(interfaceDesc) {

	if (confirm('确认删除？')) {
		doPost('InterfaceDelete', '{"desc":"' + interfaceDesc + '"}');
	}

	getInterfaceConfig();

	console.info('delInterfaceConfig done');
}

// 改
function setInterfaceConfig(interfaceDesc) {

	// {"desc":"desc", "isautocreatejmx":"isautocreatejmx", "jmeter_script_path":"jmeter_script_path", "gatling_script_path":"gatling_script_path", "method":"method", "url_protocol":"url_protocol", "url_host":"url_host", "url_port":"url_port", "url_path":"url_path", "headers":"headers", "body":"body", "responseContain":"responseContain", "boards":"boards", "maxdelay":"maxdelay"}

	var headers = document.getElementById(interfaceDesc + "_headers").textContent;
	var method = document.getElementById(interfaceDesc + "_method").textContent;
	var isAutoScript = document.getElementById(interfaceDesc + "_isAutoScript").textContent;
	var bodyStr = document.getElementById(interfaceDesc + "_bodyStr").textContent;
	var boards = document.getElementById(interfaceDesc + "_boards").textContent;
	var jmeterScriptPath = document.getElementById(interfaceDesc + "_jmeter_script_path").textContent;
	var maxDelay = document.getElementById(interfaceDesc + "_maxdelay").textContent;
	var gatlingScriptPath = document.getElementById(interfaceDesc + "_gatling_script_path").textContent;
	var responseContain = document.getElementById(interfaceDesc + "_responseContain").textContent;
	var urlStr = document.getElementById(interfaceDesc + "_url").textContent;

	var bodyJson = {};
	bodyJson.desc = interfaceDesc;
	bodyJson.isautocreatejmx = isAutoScript;
	bodyJson.jmeter_script_path = jmeterScriptPath;
	bodyJson.gatling_script_path = gatlingScriptPath;
	bodyJson.method = method;
	bodyJson.urlStr = urlStr;
	bodyJson.headersLinkJson = headers;
	bodyJson.body = bodyStr;
	bodyJson.responseContain = responseContain;
	bodyJson.boards = boards;
	bodyJson.maxdelay = maxDelay;

	console.info(bodyJson);

	doPost('InterfaceModify', JSON.stringify(bodyJson));

	getInterfaceConfig();

	console.info('setInterfaceConfig done');
}

// 查
function getInterfaceConfig() {

	var responseJson = doPost('InterfaceGet', '{}');
	var length = getJsonArryLength(responseJson);

	var innerHtml = '';
	for (var i in responseJson) {
		var interfaceJson = responseJson[i];

		var interfaceDesc = interfaceJson.interfaceDesc;
		var headers = JSON.stringify(interfaceJson.headers);
		var method = interfaceJson.method;
		var isAutoScript = interfaceJson.isAutoScript;
		var bodyStr = interfaceJson.bodyStr;
		var boards = interfaceJson.boards;
		var jmeterScriptPath = interfaceJson.jmeterScriptPath;
		var maxDelay = interfaceJson.maxDelay;
		var gatlingScriptPath = interfaceJson.gatlingScriptPath;
		var responseContain = interfaceJson.responseContain;

		var url_protocol = interfaceJson.url_protocol;
		var url_port = interfaceJson.url_port;
		var url_host = interfaceJson.url_host;
		var url_path = interfaceJson.url_path;

		var urlStr = url_protocol + '://' + url_host + ':' + url_port + url_path

		innerHtml = innerHtml + '<tr><td id="' + interfaceDesc + '_desc">' + interfaceDesc + '</td><td class="' +
			interfaceDesc + '" id="' +
			interfaceDesc + '_isAutoScript">' + isAutoScript + '</td><td class="' + interfaceDesc + '" id="' + interfaceDesc +
			'_jmeter_script_path">' + jmeterScriptPath + '</td><td class="' + interfaceDesc + '" id="' + interfaceDesc +
			'_gatling_script_path">' +
			gatlingScriptPath + '</td><td class="' + interfaceDesc + '" id="' + interfaceDesc + '_method">' + method +
			'</td><td class="' + interfaceDesc + '" id="' + interfaceDesc + '_url">' + urlStr + '</td><td class="' +
			interfaceDesc + '" id="' + interfaceDesc +
			'_headers">' + headers + '</td><td class="' + interfaceDesc + '" id="' + interfaceDesc + '_bodyStr">' + bodyStr +
			'</td><td class="' + interfaceDesc + '" id="' + interfaceDesc + '_responseContain">' + responseContain +
			'</td><td class="' + interfaceDesc + '" id="' +
			interfaceDesc + '_boards">' + boards + '</td><td class="' + interfaceDesc + '" id="' + interfaceDesc + '_maxdelay">' +
			maxDelay +
			'</td><td><button class="btn btn-xs btn-success"><i class="icon-ok" onclick="setInterfaceConfig(\'' + interfaceDesc +
			'\')"></i></button> <button class="btn btn-xs btn-warning"><i class="icon-pencil" onclick="setContenteditableByClass(\'' +
			interfaceDesc +
			'\')"></i></button> <button class="btn btn-xs btn-danger"><i class="icon-remove" onclick="delInterfaceConfig(\'' +
			interfaceDesc + '\')"></i></button></td></tr>';
	}
	innerHtml = innerHtml +
		'<tr><td contenteditable="true" id="newdesc">请新增名称，不能重复</td><td contenteditable="true" id="newisautocreatejmx">false</td><td contenteditable="true" id="newjmeter_script_path">脚本在script/jmeter中的路径</td><td contenteditable="true" id="newgatling_script_path">脚本在script/galting/user-files/simulations中的路径</td><td contenteditable="true" id="newmethod">POST</td><td contenteditable="true" id="newurl">http://xxx.xxx.xx:xx/xx/xx</td><td contenteditable="true" id="newheaders">{"key_3":"value_3","key_2":"value_2","key_1":"value_1"}</td><td contenteditable="true" id="newbody">bodybodybodybodybody</td><td contenteditable="true" id="newresponseContain">填写响应中应当包含的内容，多个用英文逗号隔开</td><td contenteditable="true" id="newboards">board1,board2,board3,board4</td><td contenteditable="true" id="newmaxdelay">2000</td><td><button class="btn btn-xs btn-success"><i class="icon-ok" onclick="addInterfaceConfig()"></i></button></td></tr>';

	document.getElementById('tbody').innerHTML = innerHtml;

	console.info('getInterfaceConfig done: ' + responseJson);
}

/**---------------------接口配置文件 End-----------------------**/

/**---------------------版本列表操作 End-----------------------**/

// 这个方法只进行初始化侧边栏中接口详情的界面，没有其他动作
function getVersionInfo() {

	var responseJson = doPost('VersionGet', '{}');
	console.info('getVersionInfo done...' + responseJson);

	var innerHtml = '';
	for (var i in responseJson) {
		var versionJson = responseJson[i];

		innerHtml = innerHtml + '<tr><td>#</td><td id="' + versionJson.version + '_version">' + versionJson.version +
			'</td><td><button class="btn btn-xs btn-success"><a style="color:#ffffff;" href="interfaces.html?version=' +
			versionJson.version +
			'"><i class="icon-ok" onclick=""></i></a></button>&nbsp;<button class="btn btn-xs btn-danger"><i class="icon-remove" onclick="delVersionInfo(\'' +
			versionJson.version + '\')"></i></button></td></tr>';
	}

	document.getElementById('historytbody').innerHTML = innerHtml;
}

// 删除一个版本的数据
function delVersionInfo(version) {

	if (confirm('确认删除？')) {
		doPost('VersionDelete', '{"version":"' + version + '"}');
	}

	getVersionInfo();

	console.info('delVersionInfo: ' + version)
}

// 版本数据导出excel（后端完成，待设计）
function versionToExcel() {

}

// 版本数据导出测试报告（后端完成，待设计）
function versionReport() {

}

/**---------------------版本列表操作 End-----------------------**/

/**---------------------版本概要操作生成 End-----------------------**/

function getInterfaceOfVersion(version) {

	// VersionInterfaces
	var responseJson = doPost('VersionInterfaces', '{"version":"' + version + '"}');
	console.info('getInterfaceOfVersion done...' + responseJson);

	var interfacelistInner = '';

	for (var i in responseJson) {
		var interfacesJson = responseJson[i];

		var interfaceDesc = interfacesJson.interface;
		var boards = interfacesJson.boards;
		var tools = interfacesJson.tools;

		interfacelistInner = interfacelistInner + '<li><a href="interfacedetail.html?version=' + version + '&interfaceDesc=' +
			interfaceDesc + '&tools=' + tools + '&boards=' + boards + '" id="' + interfaceDesc + 'aid">' + interfaceDesc + '</a></li>';
	}

	document.getElementById('interfacelist').innerHTML = interfacelistInner;
}

function delInterfaceOfVersion(interfaceDesc, version) {

	if (confirm('确认删除？')) {

	}

	getInterfaceOfVersion(version);

	console.info('delInterfaceOfVersion 暂不提供，防止误操作');
}

/**---------------------版本概要页面生成 End-----------------------**/

/**---------------------测试执行 End-----------------------**/

function getInterfacesFromConfig(){
	
		var responseJson = doPost('InterfaceGet', '{}');
		var length = getJsonArryLength(responseJson);
	
		var innerHtml = '';
		for (var i in responseJson) {
			var interfaceJson = responseJson[i];
	
			// 这里面有许多属性基本用不到，但是先写出来，方便以后增加
			var interfaceDesc = interfaceJson.interfaceDesc;
			var headers = JSON.stringify(interfaceJson.headers);
			var method = interfaceJson.method;
			var isAutoScript = interfaceJson.isAutoScript;
			var bodyStr = interfaceJson.bodyStr;
			var boards = interfaceJson.boards;
			var jmeterScriptPath = interfaceJson.jmeterScriptPath;
			var maxDelay = interfaceJson.maxDelay;
			var gatlingScriptPath = interfaceJson.gatlingScriptPath;
			var responseContain = interfaceJson.responseContain;
	
			var url_protocol = interfaceJson.url_protocol;
			var url_port = interfaceJson.url_port;
			var url_host = interfaceJson.url_host;
			var url_path = interfaceJson.url_path;
	
			var urlStr = url_protocol + '://' + url_host + ':' + url_port + url_path
			
			innerHtml = innerHtml + '<tr><td><input type="checkbox" name="checkinterfaces" value="' + interfaceDesc + '"></td><td>' + interfaceDesc + '</td><td>默认：10,20,50,100,200</td><td><input type="radio" name="' + interfaceDesc + '" value="Galting" checked>Galting<input type="radio" name="' + interfaceDesc + '" value="Jmeter">Jmeter</td></tr>';
			}
			
			document.getElementById('interfacelisttable').innerHTML = innerHtml;
}

function startTest(){
	
	// $('input:radio[name="list"]:checked').val();
	
	var checkedinterface = getChecked('checkinterfaces');
	
	for (var i in checkedinterface) {
		checkedinterface[i].tool = $('input:radio[name="' + checkedinterface[i].interface + '"]:checked').val();
	}
	
	var runinfo = doPost('StartTest', JSON.stringify(checkedinterface));
	
	alert(runinfo.message);
	
	console.info(checkedinterface);
}

function stopTest(){
	
	var runinfo = doPost('StopTest', '{}');
	
	alert(runinfo.message);
}

function logrefush(){
	
	var selectobj = document.getElementById("loglevelselect"); //定位id
	var index = selectobj.selectedIndex; // 选中索引
	var loglevel = selectobj.options[index].text; // 选中文本
	
	var ele = document.getElementById('logtextarea');
	
	ele.innerText = doPostStr('LogReader', '{"loglevel":"' + loglevel + '"}');
	
	ele.scrollTop = ele.scrollHeight;
}
/**---------------------测试执行 End-----------------------**/